package com.wc.fortnight_blue_bridge.Q241005.C_云顶天宫;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/5 19:33
 * @description https://www.lanqiao.cn/problems/19862/learning/?contest_id=210
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010, P = 998244353;
    // f[i] 表示第 i 位置是否为 m 的个数, 并且前面是否有的个
    static long[][][] f = new long[N][2][2];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        f[1][1][1] = 1;
        f[1][0][0] = m - 1;
        for (int i = 2; i <= n; i++) {
            f[i][0][1] = (m - 1) * (f[i - 1][0][1] + f[i - 1][1][1]) % P;
            f[i][0][0] = (m - 1) * f[i - 1][0][0] % P;
            f[i][1][1] = (f[i - 1][0][1] + f[i - 1][0][0]) % P;
        }
        out.println((f[n][0][1] + f[n][1][1]) % P);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
